/** @file Tools.js
@brief The tools properties and methods for colors and dynamic objects.

The tools library defines methods and properties that are used to update
dinamycally the properties of the compound objects.
Using this strategy the loader does not need to manage too many properties
but only the essential elements should be customized by the caller program.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

.pragma library

var obj_dir = "objects/"

// Prefies and suffixes for the objects
var button = "btn_";
var icon = "ico_";
var level = "level_"

// Structure limits
var tb_maxButtons = 20;     // max number of buttons in a toolbar

// Proportional ratio values
var tb_height = 0.20;       // Toolbar height to the viewer height
var tb_btnSize = 0.95;      // Buttons size ratio to toolbar height
var tb_btnSpacer = 0.15;    // Spacing ratio to the button size
var tb_iconSize = 0.80;     // Icon bigger size ratio to the button size

/*
  @fn getToolbarButtonsWidth(var, var)
  @brief calculate the size of the toolbar buttons strip.
  @param numButtons Number of buttons in the toolbar
  @param size Size of a single button
  @return The size of the buttons strip + the left and right spacer.
  */
function getToolbarButtonsWidth(buttons, size) {
        var spacePix = size * tb_btnSpacer * (buttons +1);
        return Math.round( (buttons * size) + spacePix );
        }

/*
  @fn getToolbarHeight(var)
  @brief calculate the height of the toolbar buttons strip.

  The height of the toolbar is calculated with a growth reduction
  factor. The reason is to avoid too big toolbars (and consequently
  the buttons) growing the height of the view (screen or window)
  and to avoid too small toolbars with small screens.
  The growing control is based on the inverse of the screen height

  @param view_height current height of the view
  @return The height of the buttons strip
  */
function getToolbarHeight(view_height) {
    // calculate the height based on the window height
    var brute_height = Math.round(view_height * tb_height);
    // Apply the growth control
    var growth_control = Math.log(view_height) / 15;

    return Math.round(brute_height * growth_control)
}

/*
  @fn getToolbarWidth(var, var, var)
  @brief calculate the width of the toolbar buttons strip.

  The width of the toolbar depends on the number of buttons.
  Due that the width should always be at least large as the view size
  if the calculated with based on the buttons size is shorter than
  the view the view width is returned.

  @param buttons number of buttons in the toolbar
  @param view_width size of the view where the toolbar is shown
  @param b_size size of the button
  @return The width of the toolbar strip
  */
function getToolbarWidth(buttons, view_width, b_size) {
    var calc_width = getToolbarButtonsWidth(buttons, b_size);
    if ( calc_width < view_width )
        return view_width;
    else
        return calc_width;
}

/*
  @fn getIcon(var)
  @brief Create the full file name of the icon

  @param name the symbolic icon name
  @return The full-path icon file name
  */
function getIcon(name) {
    return obj_dir + "ico_" + name + ".png"
}

/*
  @fn getButton(var)
  @brief Create the full file name of the button

  @param style the symbolic button style name
  @return The full-path button file name
  */
function getButton(style) {
    return obj_dir + "btn_" + style + ".png"
}

/*
  @fn getToolbarWidth(var)
  @brief calculate the size of the toolbar buttons.

  The size of the buttons depends is a ratio of the toolbar height.

  @param t_height The height of the toolbar
  @return The size of the button
  */
function getButtonSize(t_height) {

    console.log("getButtonSzie->toolbarHeight: " + t_height)

    return Math.round(t_height * tb_btnSize )
}

// Symbolic redefintion of colors
var black = "#000000";
var white = "#ffffff";
var dark = "#101112";
var light = "#f0f1f2";
var green = "#62b700";
var orange = "#ea650a";
var lightblue = "#09a7cc";
var blue = "#007dc9";
var purple = "#e800a1";
var violet = "#870cba";
var gray = "#808080";

// Style names
var hidden_button = "ghost";
var style_black = "black";
var style_white = "white";
var style_dark = "dark";
var style_light = "light";
var style_green = "green";
var style_orange = "orange";
var style_lightblue = "lightblue";
var style_blue = "blue";
var style_purple = "purple";
var style_violet = "violet";
var style_gray = "gray";

